package logic

import (
	"cart_srv/models/redis"
	"context"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SumCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSumCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SumCartLogic {
	return &SumCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SumCartLogic) SumCart(in *cart.SumCartRequest) (*cart.SumCartResponse, error) {
	// todo: add your logic here and delete this line

	_, count, sum, _ := redis.SumCart(int(in.UserId))

	return &cart.SumCartResponse{Count: int32(count), Amount: float32(sum)}, nil
}
